package com.itheima.dubbo.web;

import com.itheima.dubbo.UserFace;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 * 重试次数：如何设置重试，该怎么考虑？
 *  * 幂等性：多次相同的请求，得到的结果一致的
 *  * 请求：get/delete/put    post:非幂等性操作
 */
@RestController
@RequestMapping("user")
public class UserController {

//    @DubboReference(timeout = 6000)
//    @DubboReference(version = "2.0.0")
//    @DubboReference
//    @DubboReference(retries = 1)
//    @DubboReference(loadbalance = "random")
    @DubboReference(check = false)
    private UserFace userFace;

    @GetMapping("/hello")
    public String hello(String username) {

        RpcContext.getContext().setAttachment("userId", "231231");

        return userFace.hello(username);
    }

    @GetMapping("findByUser")
    public User findByUser() {
        User user = User.builder().id(111L).age(20).name("itheima").build();
        return userFace.findByUser(user);
    }
}
